package com.share.example.bcs.common.protocol.tcp;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.CharsetUtil;

public class MsgBodyEncoder extends MessageToByteEncoder {

    @Override
    protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
        byte[] data = (byte[]) msg;
        String toPackage = MsgBody.toPackage(data);//打包为协议结构
        ByteBuf sendData = Unpooled.copiedBuffer(toPackage, CharsetUtil.UTF_8);
        out.writeBytes(sendData);
    }
}
